home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86a.arc / PRIMER.DOC < prev    next >
Encoding:
Text File  |  1986-08-13  |  10.1 KB  |  210 lines

  1. ---PRIMER.DOC---
  2.  
  3. What is A86?
  4.  
  5. A86 is the name of Eric Isaacson's assembly language for the Intel 86-family
  6. of (IBM-PC and compatible) computers. Statements written in this language are
  7. used to specify machine instructions for the 86-family and to allocate memory
  8. space for program data.  These human-readable statements are translated into a
  9. machine-readable form by a program called the A86 assembler. The input to the
  10. assembler is a source file (or a list of source files) containing assembly
  11. language statements.  The output of the assembler is a file containing binary
  12. program code that can be run as a program on the PC.
  13.  
  14.  
  15. Elements of the A86 Assembly Language
  16.  
  17. The statements in an A86 source file can be classified in three general
  18. categories: instruction statements, data allocation statements, and assembler
  19. directives.  An instruction statement uses an easily-remembered name (a
  20. mnemonic) and possibly one or more operands to specify a machine instruction to
  21. be generated.  A data allocation statement reserves, and optionally
  22. initializes, memory space for program data.  An assembler directive is a
  23. statement that gives special instructions to the assembler.  Directives are
  24. unlike the instruction and data allocation statements in that they do not
  25. specify the actual contents of memory.  Examples of the three types of A86
  26. statements are given below.  These are provided to give you a general idea of
  27. what the different kinds of statements look like.
  28.  
  29.  
  30. Instruction Statements
  31.  
  32. MOV AX,BX
  33. CALL SORT_PROCEDURE
  34. ADD AL,7
  35.  
  36.  
  37. Data Allocation Statements
  38.  
  39. A_VARIABLE DW 0
  40. DB 'HELLO'
  41.  
  42.  
  43. Assembler Directives
  44.  
  45. CODE SEGMENT
  46. ITEM_COUNT EQU 5
  47.  
  48.  
  49. The statements in an A86 source file are made up of keywords, identifiers,
  50. numbers, strings, special characters, and comments.  A keyword is a symbol that
  51. has special meaning to the assembler, such as an instruction mnemonic (MOV,
  52. CALL) or some other reserved word in the assembly language (DB, SEGMENT, EQU).
  53. Identifiers are programmer-defined symbols, used to represent such things as
  54. variables, labels in the code, and numerical constants.  Identifiers may contain
  55. letters, numbers, and the characters _, @, $, and ?, but must begin with a
  56. letter, _, or @. The identifier name is considered unique up to 31 characters,
  57. but it can be of any length (up to 255 characters).   Examples of identifiers
  58. are: COUNT, L1, and A_BYTE.
  59.  
  60. Numbers in A86 may be expressed as decimal, hexadecimal, octal, or binary.
  61. These must begin with a decimal digit and, except in the case of a decimal or
  62. hexadecimal number, must end with "x" followed by a letter identifying the base
  63. of the number.  A number without an identifying base is hexadecimal if the first
  64. digit is 0; decimal if the first digit is 1 through 9.  Examples of A86 numbers
  65. are: 123 (decimal), 0ABC (hexadecimal), 1776xQ (octal), and 10100110xB (binary).
  66.  
  67. Strings are characters enclosed in single-quotes.  Examples of strings are: '1st
  68. string' and 'SIGN-ON MESSAGE, V1.0'.  The single-quote is one of many special
  69. characters used in the assembly language.  Others, run together in a list, are:
  70. $?;:=,[].+-()*/>.  The space and tab characters are also special characters,
  71. used as separators in the assembly language.
  72.  
  73. A comment is a sequence of characters used for program documentation only; it is
  74. ignored by the assembler.  Comments begin with a semicolon (;) and run to the
  75. end of the line on which they are started.  Examples of lines with comments are
  76. shown below:
  77.  
  78. ; This entire line is a comment.
  79. MOV AX,BX  ; This is a comment next to an instruction statement.
  80.  
  81. Alternatively, for compatibility with IBM's assembler, I provide the COMMENT
  82. directive.  The next non-blank character after COMMENT is a delimiter to a
  83. comment that can run across many lines; all text is ignored, until a second
  84. instance of the demiliter is seen.  For example,
  85.  
  86. COMMENT 'This comment
  87. runs across two lines'
  88.  
  89. I don't like COMMENT, becuase I think it's very dangerous.  If, for example,
  90. you have two COMMENTs in your program, and you forget to close the first one,
  91. the assembler will happily ignore all source code between the comments.  If
  92. that source code does not happen to contain any labels referenced elsewhere,
  93. the error may not be detected until your program blows up.  For multiline
  94. comments, I urge you to simply start each line with a semicolon.
  95.  
  96.  
  97. Statements in the A86 are line-oriented, which means that statements may not be
  98. broken across line boundaries.  A86 source lines may be entered in a free-form
  99. fashion; that is, without regard to the column-orientation of the symbols and
  100. special characters.
  101.  
  102. PLEASE NOTE: Because an A86 line is free-formatted, there is no need for you to
  103. put the operands to your instructions in a separate column!  The only reason
  104. that 99% of the assembly-language programs out there in the world have opernads
  105. in a separate column is that some IBM assembler written back in 1953 required
  106. it.  It makes no sense to have operands in a spearate column, so STOP DOING IT!
  107.  
  108.  
  109. Opreand Typing and Code Generation
  110.  
  111. A86 is a strongly typed assembly language.   What this means is that operands to
  112. instructions (registers, variables, labels, constants) have a type attribute
  113. associated with them which tells the assembler something about them.  For
  114. example, the operand 4 has type number, which tells the assembler that it is a
  115. numerical constant, rather than a register or an address in the code or data.
  116. The following discussion explains the types associated with instruction operands
  117. and how this type information is used to generate particular machine opcodes
  118. from general purpose instruction mnemonics.
  119.  
  120. Registers
  121.  
  122. The 8086 has 8 general-purpose word registers: AX,BX,CX,DX,SI,DI,BP, and SP.
  123. The first four of those registers are subdivided into 8 general-purpose byte
  124. registers AH,AL,BH,BL,CH,CL,DH, and DL.  There are also 4 16-bit segment
  125. registers CS,DS,ES, and SS, used for addressing memory; and the implicit
  126. instruction-pointer register.
  127.  
  128. Variables
  129.  
  130. A variable is a unit of program data with a symbolic name, residing at a
  131. specific location in 8086 memory.  A variable is given a type at the time it is
  132. defined, which indicates the number of bytes associated with its symbol.
  133. Variables defined with a DB statement are given type BYTE (one byte), and those
  134. defined with the DW statement are given type WORD (two bytes).  Examples:
  135.  
  136. BYTE_VAR DB 0   ; A byte variable.
  137. WORD_VAR DW 0   ; A word variable.
  138.  
  139.  
  140. Labels
  141.  
  142. A label is a symbol referring to a location in the program code.  It is defined
  143. as an identifier, followed by a colon (:), used to represent the location of a
  144. particular instruction or data structure.  Such a label may be on a line by
  145. itself or it may immediately precede an instruction statement (on the same
  146. line).  In the following example, LABEL_1 and LABEL_2 are both labels for the
  147. MOV AL,BL instruction.
  148.  
  149. LABEL_1:
  150. LABEL_2: MOV AL,BL
  151.  
  152. In the A86 assembly language, labels have a type identical to that of
  153. constants.  Thus, the instruction MOV BX,LABEL_2 is accepted, and the code
  154. to move the immediate constant address of LABEL2 into BX, is generated.
  155.  
  156. IMPORTANT: you must understand the distinction between a label and a variable,
  157. because you may generate a different instruction than you intended if you
  158. confuse them.  For example, if you declare  X: DW ?, the colon following the X
  159. means that X is a label; the instruction MOV SI,X moves the immediate constant
  160. address of X into the SI register.  On the other hand, if you declare X DW ?,
  161. with no colon, then X is a word variable; the same instruction MOV SI,X now does
  162. something different: it loads the run-time value of the memory word X into the
  163. SI register.
  164.  
  165.  
  166. Constants
  167.  
  168. A constant is a numerical value computed from an assembly-time expression.  For
  169. example, 123 and 3 + 2 - 1 both represent constants.  A constant differs from an
  170. a variable in that it specifies a pure number, known by the assembler before the
  171. program is run, rather than a number fetched from memory when the program is
  172. running.
  173.  
  174.  
  175. Generating Opcodes from General Purpose Mnemonics
  176.  
  177. My A86 assembly language is modeled after Intel's 8086 language, which uses
  178. general purpose mnemonics to represent classes of machine instructions rather
  179. than having a different mnemonic for each opcode.  For example, the MOV mnemonic
  180. is used for all of the following: move byte register to byte register, load word
  181. register from memory, load byte register with constant, move word register to
  182. memory, move immediate value to word register, move immediate value to memory,
  183. etc.  This feature saves you from having to distinguish "move" from "load,"
  184. "move constant" from "move memory," "move byte" from "move word," etc.
  185.  
  186. Because the same general purpose mnemonic can apply to several different machine
  187. opcodes, A86 uses the type information associated with an instruction's
  188. operands in determining the particular opcode to produce.  The type information
  189. associated with instruction operands is also used to discover programmer errors,
  190. such as attempting to move a word register to a byte register.
  191.  
  192. The examples that follow illustrate the use of operand types in generating
  193. machine opcodes and discovering programmer errors.  In each of the examples, the
  194. MOV instruction produces a different 8086 opcode, or an error.  The symbols used
  195. in the examples are assumed to be defined as follows: BVAR is a byte variable,
  196. WVAR is a word variable, and LAB is a label.  As you examine these MOV
  197. instructions, notice that, in each case, the operand on the right is considered
  198. to be the source and the operand on the left is the destination.  This is a
  199. general rule that applies to all two-operand instruction statements.
  200.  
  201. MOV AX,BX     ; (8B) Move word register to word register.
  202. MOV AX,BL     ; ERROR: Type conflict (word,byte).
  203. MOV CX,5      ; (B9) Move constant to word register.
  204. MOV BVAR,AL   ; (A0) Move AL-register to byte in memory.
  205. MOV AL,WVAR   ; ERROR: Type conflict (byte,word).
  206. MOV LAB,5     ; ERROR: Can't use a label/constant as destination to MOV.
  207. MOV WVAR,SI   ; (89) Move word register to word in memory.
  208. MOV BL,1024   ; ERROR: Constant is too large to fit in a byte.
  209.  
  210.